using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace TweakSP.Web.Application
{
    public partial class TweakSP_GetListSchema : LayoutsPageBase
    {
        private string ListId
        {
            get
            {
                return Request["LISTID"];
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            string script = string.Empty;

            Response.Clear();
            Response.ContentType = "text/xml";

            script = GetListSchema();

            if (string.IsNullOrEmpty(script))
            {
                Response.Write("Unable to download List Schema");
            }
            else
            {
                Response.Write(script);
            }

            Response.End();
        }

        private string GetListSchema()
        {
            string listXml = string.Empty;

            System.Guid listGuid = new Guid(ListId);

            SPWeb web = SPControl.GetContextWeb(Context);

            SPList list = web.Lists[listGuid];

            listXml = list.SchemaXml.ToString();

            return listXml;
        }

    }
}
